package org.example.promptword.common;


import java.sql.Timestamp;
import java.time.*;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.concurrent.TimeUnit;

/**
 *
 */
public class DateTimeUtil {

    //joda-time

    //str->Date
    //Date->str
    public static final String STANDARD_FORMAT = "yyyy-MM-dd HH:mm:ss";
    public static final String YMD_FORMAT = "yyyy-MM-dd";
    public static final String MILLI_FORMAT = "yyyyMMddHHmmssSSS";
    public static final String SECOND_FORMAT = "yyyyMMddHHmmss";
    public static final String YMDHM_CHINA = "yyyy年MM月dd日 HH:mm";
    public static final String YMDHM_CROSS = "yyyy-MM-dd HH:mm";
    public static final String YMD_NOTHING = "yyyyMMdd";
    public static final String MD_NOTHING = "MMdd";


    /**
     * 1970-01-01 08:00:01的Date
     */
    public static final Date BASE_TIME = new Date(1000L);


    private static ThreadLocal<DateFormat> standardThreadLocal = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {

            return new SimpleDateFormat(STANDARD_FORMAT);
        }
    };

    private static ThreadLocal<DateFormat> ymdThreadLocal = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {

            return new SimpleDateFormat(YMD_FORMAT);
        }
    };

    private static ThreadLocal<DateFormat> milliThreadLocal = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {

            return new SimpleDateFormat(MILLI_FORMAT);
        }
    };

    private static ThreadLocal<DateFormat> secondThreadLocal = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {

            return new SimpleDateFormat(SECOND_FORMAT);
        }
    };

    private static ThreadLocal<DateFormat> ymdhmThreadLocal = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {

            return new SimpleDateFormat(YMDHM_CHINA);
        }
    };

    private static ThreadLocal<DateFormat> ymdNothingThreadLocal = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {

            return new SimpleDateFormat(YMD_NOTHING);
        }
    };

    private static ThreadLocal<DateFormat> mdNothingThreadLocal = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {

            return new SimpleDateFormat(MD_NOTHING);
        }
    };

    private static ThreadLocal<DateFormat> ymdhmCrossThreadLocal = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {

            return new SimpleDateFormat(YMDHM_CROSS);
        }
    };


    public static Date standardParse(String dateStr) throws ParseException {
        return standardThreadLocal.get().parse(dateStr);
    }

    public static Date ymdParse(String dateStr) throws ParseException {
        return ymdThreadLocal.get().parse(dateStr);
    }

    public static Date milliParse(String dateStr) throws ParseException {
        return milliThreadLocal.get().parse(dateStr);
    }

    public static Date secondParse(String dateStr) throws ParseException {
        return secondThreadLocal.get().parse(dateStr);
    }

    public static Date ymdhmParse(String dateStr) throws ParseException {
        return ymdhmThreadLocal.get().parse(dateStr);
    }

    public static Date ymdhmFormatParse(String dateStr) throws ParseException {
        return ymdhmCrossThreadLocal.get().parse(dateStr);
    }

    public static Date ymdNothingFormatParse(String dateStr) throws ParseException {
        return ymdNothingThreadLocal.get().parse(dateStr);
    }

    public static Date mdNothingFormatParse(String dateStr) throws ParseException {
        return mdNothingThreadLocal.get().parse(dateStr);
    }

    public static String standardFormat(Date date) {
        return standardThreadLocal.get().format(date);
    }
    public static String standardFormat(LocalDateTime date) {
        java.time.format.DateTimeFormatter formatter = java.time.format.DateTimeFormatter.ofPattern(STANDARD_FORMAT);
        return date.format(formatter);
    }


    public static String ymdFormat(Date date) {
        return ymdThreadLocal.get().format(date);
    }

    public static String milliFormat(Date date) {
        return milliThreadLocal.get().format(date);
    }

    public static String secondFormat(Date date) {
        return secondThreadLocal.get().format(date);
    }

    public static String ymdhmFormat(Date date) {
        return ymdhmThreadLocal.get().format(date);
    }

    public static String ymdhmCrossFormat(Date date) {
        return ymdhmCrossThreadLocal.get().format(date);
    }

    public static String ymdNothingFormat(Date date) {
        return ymdNothingThreadLocal.get().format(date);
    }

    public static String mdNothingFormat(Date date) {
        return mdNothingThreadLocal.get().format(date);
    }

    public static Date strToDate(String dateTimeStr, String formatStr) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(formatStr);
        DateTime dateTime = dateTimeFormatter.parseDateTime(dateTimeStr);
        return dateTime.toDate();
    }

    //返回明天的日期，时间为00：00：00
    public static Date getAgo(Integer day) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, day);//把日期往后增加一天.整数往后推,负数往前移动
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    //返回明天的日期，时间为00：00：00
    public static Date getTomorrow() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, 1);//把日期往后增加一天.整数往后推,负数往前移动
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    public static Date setDateHour(Date date, int hour) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    public static Date noDelimiterStrToDate(String noDelimiterStr) throws ParseException {
        SimpleDateFormat oldFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        SimpleDateFormat newFormat = new SimpleDateFormat(STANDARD_FORMAT);
        return newFormat.parse(newFormat.format(oldFormat.parse(noDelimiterStr)));
    }

    public static Date getTomorrow(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, 1);//把日期往后增加一天.整数往后推,负数往前移动
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    //返回7天前的日期，时间为00：00：00
    public static Date getSevenDaysAgo() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -7);//把日期往后增加一天.整数往后推,负数往前移动
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    //返回明天的日期，时间为00：00：00
    public static Date getThirtyDaysAgo() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -30);//把日期往后增加一天.整数往后推,负数往前移动
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    //返回前多少天的日期，时间为00：00：00
    public static Date getDaysAgo(Integer amount) {
        Calendar calendar = Calendar.getInstance();
        //把日期往后增加一天.整数往后推,负数往前移动
        calendar.add(Calendar.DATE, -amount);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    //返回几个月前的日期，时间为00：00：00
    public static Date getMonthAgo(Integer num) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MONTH, -num);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    //返回昨天的日期，时间为00：00：00
    public static Date getYesterday() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1);//把日期往后增加一天.整数往后推,负数往前移动
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    /**
     * 获取昨天最迟时间
     *
     * @return
     */
    public static Date getYesterdayMax() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1);//把日期往后增加一天.整数往后推,负数往前移动
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        return calendar.getTime();
    }

    public static Date getYesterday(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, -1);//把日期往前增加一天.整数往后推,负数往前移动
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    public static Date getEarliestTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, 2018);
        calendar.set(Calendar.MONTH, 8);
        calendar.set(Calendar.DATE, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    //返回今天的日期，时间为00：00：00
    public static Date getToday() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    public static Date setMilliSecondZero(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    //返回今天的日期，时间为00：00：00
    public static Date getMax(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        return calendar.getTime();
    }

    //返回今天的日期，时间为00：00：00
    public static Date getHourMax(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        return calendar.getTime();
    }

    //返回今天的几点，
    public static int getTodayHour() {
        Calendar c = Calendar.getInstance();
        return c.get(Calendar.HOUR_OF_DAY);
    }

    public static void main(String[] args) {
        // System.out.println(DateTimeUtil.strToDate("2010-01-01 11:11:11", "yyyy-MM-dd HH:mm:ss"));
        System.out.println(getToday());
        System.out.println(getTodayHour());
        System.out.println(getTomorrow());
        System.out.println(getYesterday());
        System.out.println(getSevenDaysAgo());
        System.out.println(getThirtyDaysAgo());
        System.out.println(getEarliestTime());
        System.out.println(DateTimeUtil.standardFormat(getMonthAgo(3)));
        System.out.println(DateTimeUtil.standardFormat(getDaysAgo(31)));
        System.out.println(DateTimeUtil.standardFormat(getDaysAgo(1)));
        System.out.println(DateTimeUtil.standardFormat(getYesterdayMax()));
    }

    public static int getTodayHour(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.HOUR_OF_DAY);
    }

    public static Date getToday(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    public static Date getTodaySixHour() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 6);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    /**
     * 返回到明天的秒数或毫秒数
     *
     * @param timeUnit
     * @return
     */
    public static Long getTomorrowSecondOrMill(TimeUnit timeUnit) {
        long mill = getTomorrow().getTime() - System.currentTimeMillis();
        if (TimeUnit.MILLISECONDS.equals(timeUnit)) {
            //返回毫秒
            return mill;
        } else if (TimeUnit.SECONDS.equals(timeUnit)) {
            //返回秒
            return mill / 1000;
        } else {
            return null;
        }
    }

    /**
     * 描述 时间向前/后移动N天 正数往后推,负数往前移动
     *
     * @param time 时间
     * @param days 天数
     * @return
     */
    public static Date dayAddOrMinus(Date time, Integer days) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(time);
        // 把日期往后增加一天.正数往后推,负数往前移动
        calendar.add(Calendar.DATE, days);
        // 这个时间就是日期往后推一天的结果
        return calendar.getTime();
    }

    /**
     * 描述 时间向前/后移动N分钟 正数往后推,负数往前移动
     *
     * @param time    时间
     * @param minutes 分钟数
     * @return
     */
    public static Date minuteAddOrMinus(Date time, Integer minutes) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(time);
        // 把日期往后增加一天.正数往后推,负数往前移动
        calendar.add(Calendar.MINUTE, minutes);
        // 这个时间就是日期往后推一天的结果
        return calendar.getTime();
    }

    /**
     * 毫秒数转时间字符串
     *
     * @param date 毫秒
     * @return 转换结果
     */
    public static String stringToLongDate(Long date) {
        Date res = new Date(date);
        SimpleDateFormat sdf = new SimpleDateFormat(STANDARD_FORMAT);
        return sdf.format(res);
    }

    /**
     * 获取开播时间和现在相差的小时或天数
     *
     * @param startTime 开播时间
     * @return 计算结果
     */
    public static Double getTimeDiff(String startTime) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startDate = null;
        try {
            startDate = dateFormat.parse(startTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Integer datePoor = getDatePoor(new Date(), startDate);
        BigDecimal b = BigDecimal.valueOf((double) datePoor / 60);
        if (b.compareTo(new BigDecimal(24)) > 0) {
            b = BigDecimal.valueOf(((double) datePoor / 60) / 24);
            return b.setScale(2, RoundingMode.HALF_UP).doubleValue();
        } else {
            return b.setScale(2, RoundingMode.HALF_UP).doubleValue();
        }
    }


    public static Integer getDatePoor(Date startDate, Date endDate) {

        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - startDate.getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        Long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        // long sec = diff % nd % nh % nm / ns;
        Long mymint = diff / 1000 / 60;
        int intValue = mymint.intValue();
        return intValue;
    }

    /**
     * 获取今日前七天的日期（不包括今天）
     * @return 前七天的日期列表
     */
    public static List<LocalDate> getPreviousSevenDays() {
        LocalDate today = LocalDate.now();
        List<LocalDate> previousSevenDays = new ArrayList<>();
        for (int i = 1; i <= 7; i++) {
            LocalDate previousDay = today.minusDays(i);
            previousSevenDays.add(previousDay);
        }
        Collections.reverse(previousSevenDays);
        return previousSevenDays;
    }

    /**
     * 获取今日所在周前七周的日期（不包括本周），每周的第一天和最后一天
     * @return 前七周的日期列表，每个元素是一个包含每周第一天和最后一天的列表
     */
    public static List<List<LocalDate>> getPreviousSevenWeeks() {
        LocalDate today = LocalDate.now();
        List<List<LocalDate>> previousSevenWeeks = new ArrayList<>();
        for (int i = 1; i <= 7; i++) {
            LocalDate startOfWeek = today.minusWeeks(i).with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
            LocalDate endOfWeek = today.minusWeeks(i).with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
            List<LocalDate> weekDates = new ArrayList<>();
            weekDates.add(startOfWeek);
            weekDates.add(endOfWeek);
            previousSevenWeeks.add(weekDates);
        }
        Collections.reverse(previousSevenWeeks);
        return previousSevenWeeks;
    }

    /**
     * 获取今日所在月前七个月的日期（不包括本月），每月的第一天和最后一天
     * @return 前七个月的日期列表，每个元素是一个包含每月第一天和最后一天的列表
     */
    public static List<List<LocalDate>> getPreviousSevenMonths() {
        LocalDate today = LocalDate.now();
        List<List<LocalDate>> previousSevenMonths = new ArrayList<>();
        for (int i = 1; i <= 7; i++) {
            LocalDate startOfMonth = today.minusMonths(i).with(TemporalAdjusters.firstDayOfMonth());
            LocalDate endOfMonth = today.minusMonths(i).with(TemporalAdjusters.lastDayOfMonth());
            List<LocalDate> monthDates = new ArrayList<>();
            monthDates.add(startOfMonth);
            monthDates.add(endOfMonth);
            previousSevenMonths.add(monthDates);
        }
        Collections.reverse(previousSevenMonths);
        return previousSevenMonths;
    }

    public static String extractYearMonth(LocalDate date) {
        if (date == null) {
            throw new IllegalArgumentException("Date cannot be null");
        }
        // 使用自定义格式化器 yyyy-MM
        java.time.format.DateTimeFormatter formatter = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM");
        return date.format(formatter);
    }


    /**
     * 获取当前日期所在周从周一到现在的日期列表
     *
     */
    public static List<LocalDate> getPreviousDaysOfWeek() {
        // 获取当前日期
        LocalDate today = LocalDate.now();
        // 获取本周一的日期
        LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
        // 创建一个列表来存储日期
        List<LocalDate> dates = new ArrayList<>();
        // 添加本周一到今天的日期
        for (int i = 0; i <= today.getDayOfWeek().getValue() - startOfWeek.getDayOfWeek().getValue(); i++) {
            dates.add(startOfWeek.plusDays(i));
        }
        return dates;
    }

    /**
     * 获取当前日期所在月从一号到现在的日期列表
     *
     */
    public static List<LocalDate> getPreviousDaysOfMonth() {
        // 获取当前日期
        LocalDate today = LocalDate.now();
        // 获取当月第一天的日期
        LocalDate startOfMonth = today.withDayOfMonth(1);
        // 创建一个列表来存储日期
        List<LocalDate> dates = new ArrayList<>();
        // 添加当月第一天到今天的日期
        for (int i = 0; i <= today.getDayOfMonth() - 1; i++) {
            dates.add(startOfMonth.plusDays(i));
        }
        return dates;
    }

    // 获取当前月的开始时间
    public static Timestamp getMonthStart() {
        LocalDate today = LocalDate.now();
        LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
        LocalDateTime startOfMonth = firstDayOfMonth.atTime(LocalTime.MIDNIGHT);
        return Timestamp.valueOf(startOfMonth);
    }

    // 获取当前月的结束时间
    public static Timestamp getMonthEnd() {
        LocalDate today = LocalDate.now();
        LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
        LocalDateTime endOfMonth = lastDayOfMonth.atTime(LocalTime.of(23, 59, 59));
        return Timestamp.valueOf(endOfMonth);
    }

    // 获取当前周的开始时间
    public static Timestamp getWeekStart() {
        LocalDate today = LocalDate.now();
        LocalDate firstDayOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
        LocalDateTime startOfWeek = firstDayOfWeek.atTime(LocalTime.MIDNIGHT);
        return Timestamp.valueOf(startOfWeek);
    }

    // 获取当前周的结束时间
    public static Timestamp getWeekEnd() {
        LocalDate today = LocalDate.now();
        LocalDate lastDayOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
        LocalDateTime endOfWeek = lastDayOfWeek.atTime(LocalTime.of(23, 59, 59));
        return Timestamp.valueOf(endOfWeek);
    }

    // 获取当天的开始和结束时间
    public static Timestamp getDayStart() {
        LocalDate today = LocalDate.now();
        LocalDateTime startOfDay = today.atTime(LocalTime.MIDNIGHT);
        return Timestamp.valueOf(startOfDay);
    }

    // 获取当天的结束时间
    public static Timestamp getDayEnd() {
        LocalDate today = LocalDate.now();
        LocalDateTime endOfDay = today.atTime(LocalTime.of(23, 59, 59));
        return Timestamp.valueOf(endOfDay);
    }

    // 获取当前日期的 Date 对象
    public static Date getCurrentDate() {
        return new Date();
    }

    //获取当前时间并返回 LocalDateTime 对象
    public static LocalDateTime getCurrentLocalDateTime() {
        return LocalDateTime.now();
    }

    // 获取当前周的开始日期
    public static Date getWeekStartDate() {
        LocalDate today = LocalDate.now();
        LocalDate weekStart = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
        return Date.from(weekStart.atStartOfDay(ZoneId.systemDefault()).toInstant());
    }

    // 获取当前周的结束日期
    public static Date getWeekEndDate() {
        LocalDate today = LocalDate.now();
        LocalDate weekEnd = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
        return Date.from(weekEnd.atStartOfDay(ZoneId.systemDefault()).toInstant());
    }

    // 获取当前月的开始日期
    public static Date getMonthStartDate() {
        LocalDate today = LocalDate.now();
        LocalDate monthStart = today.with(TemporalAdjusters.firstDayOfMonth());
        return Date.from(monthStart.atStartOfDay(ZoneId.systemDefault()).toInstant());
    }

    // 获取当前月的结束日期
    public static Date getMonthEndDate() {
        LocalDate today = LocalDate.now();
        LocalDate monthEnd = today.with(TemporalAdjusters.lastDayOfMonth());
        return Date.from(monthEnd.atStartOfDay(ZoneId.systemDefault()).toInstant());
    }
}
